#以下内容来自tutorial.pdf P69 2021-3-4 14:08
def scope_test():
    def do_local():
        spam = "local spam"#即此处的spam仅限于do_local()函数中使用有效。
    def do_nonlocal():
        nonlocal spam
        spam = "nonlocal spam"#即此处的spam将在scope_test()内使用有效。
    def do_global():
        global spam
        spam = "global spam"
        print("注意此处:",spam)#即此处的spam将在do_global()内部和scope_test()外使用有效。在scope_test()中使用无效。
    spam = "test spam"
    do_local()
    print("After local assignment:", spam)
    do_nonlocal()
    print("After nonlocal assignment:", spam)
    do_global()
    print("After global assignment:", spam)
scope_test()
print("In global scope:", spam)
